package co.yixiang.yshop.module.member.controller.app.userbill;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
import co.yixiang.yshop.module.member.controller.admin.userbill.vo.UserBillPageReqVO;
import co.yixiang.yshop.module.member.controller.admin.userbill.vo.UserBillRespVO;
import co.yixiang.yshop.module.member.convert.userbill.UserBillConvert;
import co.yixiang.yshop.module.member.dal.dataobject.userbill.UserBillDO;
import co.yixiang.yshop.module.member.service.integralrule.strategy.IntegralRuleContext;
import co.yixiang.yshop.module.member.service.userbill.UserBillService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.math.BigDecimal;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
import static co.yixiang.yshop.module.member.enums.BillDetailEnum.SHARE_PRODUCTS;

/**
 * @author pepis
 * @apiNote 积分明细
 **/
@RestController
@RequestMapping("/member/user-bill")
@Tag(name = "app-积分明细")
public class AppUserBillController {
    @Resource
    private UserBillService userBillService;
    @Resource
    private IntegralRuleContext integralRuleContext;

    @GetMapping("/page")
    @Operation(summary = "获得用户账单分页")
    public CommonResult<PageResult<UserBillRespVO>> getUserBillPage(@Valid UserBillPageReqVO pageVO) {
        pageVO.setUid(SecurityFrameworkUtils.getLoginUserId());
        PageResult<UserBillDO> pageResult = userBillService.getUserBillPage(pageVO);
        return success(UserBillConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("shareGoods")
    @Operation(summary = "分享商品")
    public CommonResult<BigDecimal> shareGoods(){
        BigDecimal bigDecimal = integralRuleContext.execute(SHARE_PRODUCTS, SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(bigDecimal);
    }


}
